<?php
/**
 * Created by PhpStorm.
 * User: 郑合达
 * Date: 2019/2/25
 * Time: 15:18
 */

namespace app\admin\controller;


use think\Controller;
use app\model\DtdataModel;
use app\model\DandataModel;
class Jiwe extends Controller
{
    function WebService(){
        $de_id =10;
        $soap = new \SoapClient(null, array(
            "location" => "http://221.204.213.54/soap/beidou/BDService_baidu.php",
            "uri" => "beidou", //
            "style" => SOAP_RPC,
            "use" => SOAP_ENCODED
        ));
       $data= json_decode($soap->getGD($de_id),true);
//       dump($data['RcvTime']);die();
        //截取时间戳
        $result = array();
        preg_match_all('/(?:\()(.*)(?:\))/i',$data['RcvTime'], $result);
        $Regex = '#([^+]+)#is';
        preg_match($Regex,$result[1][0],$result);
        $data['de_id']=$data['id'];
        unset($data['id']);
        $data['RcvTime']=$result[1];
        $list= $this->curl("http://api.map.baidu.com/geocoder?location={$data['bdlat']},{$data['bdlng']}&callback=renderReverse&output=json&pois=100&key=2COzFaICuIyVj7V3VetKfmdRVnX8BhVr");
//       dump($list);die();
        $data['address']=$list['result']['formatted_address'];
        $res = DtdataModel::create($data);
         $info = DandataModel::where('de_id',$de_id)->value('id');
         if($info){
             $list = DandataModel::update($data,['id'=>$info]);
         }else{
             $list = DandataModel::create($data);
         }
//        dump($data);
    }
    /**
     * @param $url   接口连接的地址
     * @return mixed
     *  转接接口的方法
     */
    public function curl($url){
        $ch = curl_init();
        //设置选项，包括URL
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_HEADER, 0);

        //执行并获取HTML文档内容
        $output = curl_exec($ch);

        //释放curl句柄
        curl_close($ch);

        $data=json_decode($output,true);//$data就是最终的数据 而且已经转换成了数组
        return $data;
    }
    public function huoqu(){
        return view('jiwe');
    }
}
